/*
* 审批详情
* */
import 'package:center_beijing/api/component_api.dart';
import 'package:center_beijing/api/task_api.dart';
import 'package:center_beijing/common/notification.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/widgets/custom_loading_widget.dart';
import 'package:center_beijing/widgets/imagesWatch_widget2.dart';
import 'package:center_beijing/widgets/textarea_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';


class ScrapApprovalDetail extends StatefulWidget {
  @override
  _ScrapApprovalDetailState createState() => _ScrapApprovalDetailState();
}

class _ScrapApprovalDetailState extends State<ScrapApprovalDetail> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  CustomLoading loading = CustomLoading.withMessage('提交中...');
  CustomLoading loading2 = CustomLoading.withMessage('请稍候...');
  var scrapDetail = Map();
  var businessId = Get.arguments['businessId'];
  var taskId = Get.arguments['taskId'];
  var remark = '';
  var type = Get.arguments['type'];

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    this.getScrapDetail();
  }

  @override
  void dispose() {
    _controller.dispose();
    loading2.dismiss();
    super.dispose();
  }

  /*
  * 获取报废详情
  * */
  getScrapDetail() async {
    loading2.show(delay: 30);
    var pass = {'id': businessId};
    var result = await getScrapDetailHistory(pass);
    loading2.dismiss();
    if (result != null&& result['errorMessage'] == null) {
      this.setState(() {
        scrapDetail = result;
      });
    }
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('报废详情'),
        ),
        body: Container(
          color: Styles.MainBackgroundColor,
          padding: EdgeInsets.fromLTRB(
              0, 0, 0, MediaQuery.of(context).padding.bottom),
          child: SingleChildScrollView(
            child: GestureDetector(
              onTap: (){
                FocusScope.of(context).requestFocus(FocusNode());
              },
              child: Column(
                children: [
                  Container(
                    padding: EdgeInsets.fromLTRB(Styles.spacing8, Styles.spacing8,
                        Styles.spacing8, Styles.spacing8),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Container(
                              height: 26.h,
                              width: 4,
                              color: Styles.BlueColor,
                              margin: EdgeInsets.only(right: Styles.spacing8),
                            ),
                            Text(
                              '报废信息',
                              style: TextStyle(
                                  color: Styles.DetailColor,
                                  fontSize: Styles.Middle16Font),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.fromLTRB(
                        0, 0, 0, Styles.spacing8),
                    color: Colors.white,
                    child: Column(
                      children: [
                        Container(
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing8, 0, Styles.spacing8, 0),
                          margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                          child: Row(
                            children: [
                              Container(
                                child: Text(
                                  '订单项目:',
                                  style: TextStyle(
                                      color: Styles.DetailColor,
                                      fontSize: Styles.NormalFont),
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.fromLTRB(
                                    Styles.spacing8, 0, Styles.spacing8, 0),
                                child: Text(
                                  scrapDetail['orderName'] != null
                                      ? scrapDetail['orderName']
                                      : '--',
                                  style: TextStyle(
                                      color: Styles.DetailColor,
                                      fontSize: Styles.NormalFont),
                                ),
                              )
                            ],
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing8, 0, Styles.spacing8, 0),
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Container(
                                child: Text(
                                  '构件编号:',
                                  style: TextStyle(
                                      color: Styles.DetailColor,
                                      fontSize: Styles.NormalFont),
                                ),
                              ),
                              Expanded(
                                  child: Container(
                                    margin: EdgeInsets.fromLTRB(
                                        Styles.spacing8, 0, Styles.spacing8, 0),
                                    child: Text(
                                      scrapDetail['code'] != null
                                          ? scrapDetail['code']
                                          : '--',
                                      style: TextStyle(
                                          color: Styles.DetailColor,
                                          fontSize: Styles.NormalFont),
                                    ),
                                  ))
                            ],
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing8, 0, Styles.spacing8, 0),
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Container(
                                child: Text(
                                  '报废原因:',
                                  style: TextStyle(
                                      color: Styles.DetailColor,
                                      fontSize: Styles.NormalFont),
                                ),
                              ),
                              Expanded(
                                  child: Container(
                                    margin: EdgeInsets.fromLTRB(
                                        Styles.spacing8, 0, Styles.spacing8, 0),
                                    child: Text(
                                      scrapDetail['scrapCause'] != null
                                          ? scrapDetail['scrapCause']
                                          : '--',
                                      style: TextStyle(
                                          color: Styles.DetailColor,
                                          fontSize: Styles.NormalFont),
                                    ),
                                  ))
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  scrapDetail['attrList'] != null &&
                      scrapDetail['attrList'].length > 0
                      ? Container(
                    color: Colors.white,
                    padding: EdgeInsets.fromLTRB(Styles.spacing8, 0, Styles.spacing8, 0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          padding: EdgeInsets.fromLTRB(
                              0, Styles.spacing8, 0, Styles.spacing8),
                          child: Text(
                            '现场照片',
                            style: TextStyle(
                                color: Styles.DetailColor,
                                fontSize: Styles.NormalFont),
                          ),
                        ),
                        ImagesWatchWidget2(
                          photos:
                          scrapDetail['attrList'].map<String>((image) {
                            return "${GlobalConfig.baseUrl}fs/irest/file/mps_fileTransferHandler/image?id=${image['attachmentId']}&ZJQFSESSION=${GlobalConfig.session}";
                          }).toList(),
                        )
                      ],
                    ),
                  )
                      : Container(),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, Styles.spacing8),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          child: Text(
                            '是否通过:',
                            style: TextStyle(
                                color: Styles.DetailColor,
                                fontSize: Styles.NormalFont),
                          ),
                        ),
                        Expanded(
                            child: Container(
                              margin: EdgeInsets.fromLTRB(
                                  Styles.spacing8, 0, Styles.spacing8, 0),
                              child: Text(
                                scrapDetail['scrapStatusName'] != null
                                    ? scrapDetail['scrapStatusName']
                                    : '--',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.NormalFont),
                              ),
                            ))
                      ],
                    ),
                  ),
                  scrapDetail['wfTaskComments']!=null?Column(
                    children: scrapDetail['wfTaskComments'].map<Widget>((item) {
                      return Container(
                        padding: EdgeInsets.fromLTRB(
                            Styles.spacing8, 0, Styles.spacing8, 0),
                        margin: EdgeInsets.fromLTRB(
                            0, Styles.spacing4, 0, Styles.spacing4),
                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                              padding: EdgeInsets.all(Styles.spacing8),
                              decoration: BoxDecoration(
                                color: Styles.BlueColor,
                                shape: BoxShape.circle,
                              ),
                              child: Text(
                                item['taskName'],
                                style: TextStyle(
                                    color: Styles.ShareWhite,
                                    fontSize: Styles.NormalFont),
                              ),
                            ),
                            Expanded(
                                child: Container(
                                  padding: EdgeInsets.all(Styles.spacing8),
                                  margin: EdgeInsets.fromLTRB(
                                      Styles.spacing8,
                                      0,
                                      Styles.spacing8,
                                      0),
                                  decoration: BoxDecoration(
                                      color: Styles.GrayLight,
                                      borderRadius: BorderRadius.all(
                                          Radius.circular(4.0.r)),
                                      border: Border.all(
                                          width: 1,
                                          color: Styles.LineColor)),
                                  child: Column(
                                    crossAxisAlignment:
                                    CrossAxisAlignment.start,
                                    children: [
                                      Row(
                                        mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text(
                                              '由  ${item['userName']} 在 ${item['operateTimeStr']} 操作',
                                              style: TextStyle(
                                                  color: Styles.DetailColor,
                                                  fontSize:
                                                  Styles.NormalFont)),
                                        ],
                                      ),
                                      Container(
                                        padding:
                                        EdgeInsets.fromLTRB(
                                            0,
                                            0,
                                            0,
                                            Styles.spacing8),
                                        child: Text(
                                          item['approvalComments'],
                                          style: TextStyle(
                                              color: Styles
                                                  .LeftTitleColor,
                                              fontSize: Styles
                                                  .NormalFont),
                                        ),
                                      ),
                                    ],
                                  ),
                                ))
                          ],
                        ),
                      );
                    }).toList(),
                  ):Container()
                ],
              ),
            ),
          ),
        ),
        );
  }
}
